const request = require('../utils/request')
const jwt = require('../utils/jwt')

class UserController {
  // 登录接口
  static async login (ctx) {
    let { code } = ctx.request.body
    const res = await request({
			url: '/sns/jscode2session',
			method: 'get',
			params: {
				appid: 'wx1874abd185ceb332',
				secret: 'f82b890a97a0a48743e366b50816a3c9',
				js_code: code,
				grant_type: 'authorization_code'
			}
		})

		const token = jwt.createToken(res)
		ctx.body = {
			err: 0,
			msg: 'success',
			data: { token }
		}
  }

  static testApi (ctx) {
    ctx.body = {err: '0'}
  }
}

module.exports = UserController